<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id="btn">发送验证码</button>
    <script>
        var btn = document.getElementById("btn");
        var num = 5;
        btn.onclick = function(){
            var timer = setInterval(function(){
                if(num>=0){
                    btn.innerHTML = num;
                    num--;
                    btn.disabled = true;
                }
                else{
                    clearInterval(timer);
                    btn.innerHTML = "发送验证码";
                    btn.disabled = false;
                    num=5;
                }
            },1000)
        }
    </script>
</body>
</html>